<?php

class QuocgiaController extends Controller
{
	public function actionIndex()
	{
		if(isset($_REQUEST['content'])){
			echo $_REQUEST['content'];
			echo "123";
		}else{
			$this->render('index');
		}
		$this->render('index');
	}

	public function accessRules()
	{
		return array(
			array('allow',  // allow all users to perform 'index' and 'view' actions
				'actions'=>array('getlist', 'autocomplete'),
				'users'=>array('*'),
			),
			array('allow', // allow authenticated user to perform 'create' and 'update' actions
				'actions'=>array(),
				'users'=>array('@'),
			),
			array('allow', // allow admin user to perform 'admin' and 'delete' actions
				'actions'=>array('admin','generate'),
				'users'=>array('admin'),
			),
			array('deny',  // deny all users
				'users'=>array('*'),
			),
		);
	}
	
	public function actionAutocomplete() {
		$criteria = new CDbCriteria;
		$criteria->select = array('id', 'tenquocgia');
	
		$criteria->addSearchCondition('tenquocgia',  strtoupper( $_GET['term']) ) ;
		$criteria->limit = 15;
		$data = Quocgia::model()->findAll($criteria);
	
		$arr = array();
	
		foreach ($data as $item) {
			 
			$arr[] = array(
					'id' => $item->id,
					'value' => $item->tenquocgia,
					'label' => $item->tenquocgia,
			);
		}
	
		echo CJSON::encode($arr);
	
	}
	
	public function actionGenerate(){
		
	}

}